from app.models import BaseModel
from tools import db


class ApsChedulerJob(BaseModel, db.Model):
    __tablename__ = 'api_job'
    id = db.Column(db.Integer, primary_key=True)
    task_id = db.Column(db.String(50), unique=True)
    func = db.Column(db.String(128), nullable=False)
    args = db.Column(db.String(128), nullable=True)
    kwargs = db.Column(db.String(128), nullable=True)
    trigger = db.Column(db.String(128), nullable=False)
    next_run_time = db.Column(db.DateTime)
    args_dict = db.Column(db.String(256), nullable=True)
    
    
    def to_dict(self):
        return {
            'id': self.id,
            'func': self.func,
            'args': self.args,
            'kwargs': self.kwargs,
            'trigger': self.trigger,
            'task_id': self.task_id,
            'next_run_time': self.next_run_time,
            "args_dict": self.args_dict
        }